package com.benshou.bcss.common.jackson;

import com.benshou.bcss.common.j17common.annotation.NotEmpty;
import com.benshou.bcss.common.j17common.annotation.Nullable;
import com.fasterxml.jackson.databind.BeanDescription;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializationConfig;
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter;
import lombok.NonNull;

import java.util.List;

/**
 * Jackson 序列化器 自定义
 *
 * @author <a href="mailto:liuzhenbang@benshou.com">Liu Zhenbang</a>
 */
public interface JacksonSerializeCustomizer {

    /**
     * 根据上下文，尝试生成序列化器。若返回 null ，则视为生成失败。
     *
     * @param config SerializationConfig
     * @param description BeanDescription
     * @param writers 列表： BeanPropertyWriter
     * @param currentWriter 当前的 BeanPropertyWriter
     * @return 序列化器
     */
    @Nullable
    JsonSerializer<Object> tryCreateSerializer(
            SerializationConfig config,
            BeanDescription description,
            @NotEmpty List<BeanPropertyWriter> writers,
            @NonNull BeanPropertyWriter currentWriter);
}
